<template>
  <div class="container">
    <data-view
      :propViewKey="strings.defaultIfBlank(propViewKey, 'device_plan_task')"
      :propViewForm="strings.defaultIfBlank(propViewForm, 'device/device_plan_task/device_task_detail.vue')"
      :propIsTdesign="true"
      ref="dataView"
      :propAutoFetchData="false"
      :propFlowKey="propFlowKey"
      :propParam="{busType: propBusType}"
      :propViewFormTitle="cpPropViewFormTitle"
      :propHideColumns="cpPropHideColumns"
      @extra-button-click="extraButtonClick"
    />
  </div>
</template>

<script>
export default {
  desc: '设备-列表',
  props: ['propParameter', 'propFlowKey', 'propBusType', 'propViewForm', 'propViewKey'],
  mounted() {
    this.loadDtl()
  },

  data() {
    return {}
  },
  computed: {
    // 弹框标题
    cpPropViewFormTitle() {
      return this.cpBusTitle + '任务详情'
    },
    // 隐藏列
    cpPropHideColumns() {
      return []
    },
    // 隐藏列
    cpBusTitle() {
      return this.utils.getDictLabel(this.propBusType, this.constCommon.dictType.devicePlanTaskBusType, null, false)
    },
  },
  components: {},
  methods: {
    loadDtl() {
      let wrapper = this.$newWrapper()
      wrapper.eq('bus_type', this.propBusType)
      this.$refs.dataView.setQueryWrapper(wrapper)
    },
    extraButtonClick(para) {
      let buttonKey = para.button.key
      if (buttonKey === 'buildTask') {
        this.utilMessage.confirm(`是否生成${this.cpBusTitle}任务`, () => {
          this.buildTask()
        })
        return
      }
    },
    buildTask() {
      this.utilVue.loadShow(true)
      this.$ajax.get(`/device/plan_task/buildByPlan?taskbusType=${this.propBusType}`).then(resp => {
        this.utilVue.loadHide()
        if (resp.success) {
          this.utilMessage.success(resp.msg)
          this.loadDtl()
        }
      })
    }
  }
}
</script>
